/**
 * Copyright (c) 2011-2012
 * OmniCore CodeGuide
 */
package de.tum.in.oose.bumpers.control;

import de.tum.in.oose.bumpers.cars.Car;
/**
 * The list of cars.
 * 
 */
public class CarList
{
	/**
	 * setting carlist to element e.
	 * @param e the new carlist element
	 */
	public CarList(CarListElement e){
		elements = e;
	}
	
	/**
	 * Setting carlist elements to null.
	 */
	public CarList(){
		elements = null;
	}
	
	private CarListElement elements;
		
	/**
	 * @param c car to be inserted
	 */
	public void insertCar(Car c){
		elements = new CarListElement(c, elements);
	}
	
	/**
	 * @return elements is empty
	 */
	public boolean isEmpty(){
		return elements == null;
	}
	
	/**
	 * @param c the car which should be found.
	 * @return the car list element for the car c
	 */
	public CarListElement findCar(Car c){
		CarListElement current = elements;
		while(current != null && current.getCar() != c){
			current = current.getNext();
		}
		return current;
	}
		
}
